<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=basePath %>js/jquery-1.9.0.js"></script>
<script type="text/javascript" src="<%=basePath %>js/jquery.qrcode.min.js"></script>
<script type="text/javascript" src="<%=basePath %>js/jquery.Jcrop.min.js"></script>
<script type="text/javascript" src="<%=basePath %>js/ajaxfileupload.js"></script>




<title>userinfo</title>

<script type="text/javascript">

$(function(){
	
	//给textarea 赋值
	var remark_ = "${user.remark}";
	$("#remark").text(remark_);
	
	
	//TODO 手机号码校验 待修改
	$("#mobile").blur(function(){
		var mobile= $("#mobile").val();
		//校验手机号码格式是否正确
		if(mobile.length!=11){
			alert("手机号码长度不正确");
		}
	});
	
	//文本框失去焦点时执行校验邮箱格式
	$("#email").blur(function(){
		var email= $("#email").val();
		//校验邮箱格式是否正确
		if(!email.match(/^[a-z0-9]+([._]*[a-z0-9]+)*@[a-z0-9]+([_.][a-z0-9]+)+$/gi)){
			alert("邮箱格式不正确")
		}
	});
	
	//校验身份证号
	$("#identityCard").blur(function(){
		//校验身份呢证号码
		validateIdentity($("#identityCard").val());
	});
	
	
	
	
	// 上传头像
	$('#doc').on('change',function(){
		
		
		
		$.ajaxFileUpload({  
	        url:'<%=basePath%>user/upload',  
	        secureuri:false,  
	        fileElementId:'doc',//file标签的id  
	        dataType: 'json',//返回数据的类型  
	        success: function (data) { 
	        	alert("haha");
	        	debugger;
	            var obj = jQuery.parseJSON(data);  
	            $("#doc").next().attr("href", "<%=basePath%>"+obj.fileName);
	            $("#doc").next().html(obj.fileName);
	        },  
	        error: function (data, e) {  
	            alert(e);  
	        }  
	    });
	})
	
	
});

function save(){
	var mobile_ = $.trim($("#mobile").val());
	var email_ =$.trim($("#email").val());
	var username_ = $.trim($("#username").val());
	var name_ = $.trim($("#name").val());
	var identityCard_ =$.trim($("#identityCard").val());
	var telephone_ = $.trim($("#telephone").val());
	var address_ = $.trim($("#address").val());
	var remark_ =$.trim($("#remark").val());
	
	/* var userInfo={
          "mobile":mobile_,
          "email":email_,
          "username":username_,
          "name":name_,
          "identityCard":identityCard_,
          "telephone":telephone_,
          "address": address_,
          "remark": remark_
        }; */
	$.ajax({
		type : "POST",
		url : "saveuserinfo",
		data : { "mobile":mobile_,
	          "email":email_,
	          "username":username_,
	          "name":name_,
	          "identityCard":identityCard_,
	          "telephone":telephone_,
	          "address": address_,
	          "remark": remark_}, 
		success : function(result) {
			if(result.success){
				alert("更新成功");
				
			}else{
				alert("更新失败!")
			}
		},
		error : function(error) {
			alert("error")
		}

	});
}


//校验身份证号码的方法

function validateIdentity(identity){
	var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
	
	var bol = reg.test(identity);
	alert(bol);
	
}










</script>

</head>
<body>
		
		
		
		
		
		
		<%-- <form id="faceIcon" target="hid_frame" action="<%=basePath %>user/uploadImgtests" method="post" enctype="multipart/form-data">   --%>
        <input type="file" name="doc" id="doc" />  
<!--         <input type="hidden" id="x" name="x" />  
        <input type="hidden" id="y" name="y" />  
        <input type="hidden" id="w" name="w" />  
        <input type="hidden" id="h" name="h" />  
        <input type="submit" value="上传" id="upload"/>  
    </form>   -->
      
    <img alt="" src="" id="displayImg"/> 
		
		
		<br/>
		<br/>
		
		
		
		

		手机:<input type="text" id="mobile" name="mobile" value="${user.mobile}"  maxlength="11" onkeyup='this.value=this.value.replace(/\D/gi,"")' />
	
		<br/>
		邮箱:<input type="text" id="email" name="email" value="${user.email}" maxlength="32" />
		<br/>

		用户名:<input type="text" id="username" name="username" value="${user.username}" maxlength="16" />
		<br/>
		姓名:<input type="text" id="name" name="name" value="${user.name}" maxlength="32"/>
		<br/>
		身份证:<input type="text" id="identityCard" name="identityCard" value="${user.identityCard}" maxlength="18" /> 
		<br/>
		电话:<input type="text" id="telephone" name="telephone" value="${user.telephone}" maxlength="16" />
		<br/>
		
		地址:<input type="text" id="address" name="address" value="${user.address}" maxlength="200"/>
		<br/>
		
		<br/>
		<!-- 头像 -->
		
		备注:<textarea id="remark" name="remark" rows="10" cols="20" maxlength="200"></textarea>
		
		<button id="savebtn" name="savebtn" onclick="save()">保存</button>
		<button id="cancelbtn" name="cancelbtn" onclick=""> 取消</button>
		
		
		
</body>
</html>